import java.util.Arrays;

public class Test {

    public static void main(String[] args) {
        int[] array = new int[10];
        // [2,6)
        // Arrays.fill(array, 2, 6, -1);
        Arrays.fill(array, -1);
        String ret = Arrays.toString(array);
        System.out.println(ret);

    }

    public static void main12(String[] args) {
        int[] array1 = {1,2,33,4};
        int[] array2 = {1,2,3,4};
        boolean flag = Arrays.equals(array1, array2);
        System.out.println(flag);
    }

    public static void main11(String[] args) {
        int[][] array = new int[2][];
        array[0] = new int[3];
        array[1] = new int[5];

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j]);
            }
            System.out.println();
        }
    }

    public static void main10(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};

        /*System.out.println(array.length);
        System.out.println(array[0]);
        System.out.println(array[0].length);*/

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }

        System.out.println("===============================");

        for(int[] a : array){
            for(int x : a){
                System.out.print(x + " ");
            }
            System.out.println();
        }

        System.out.println("===============================");

        String ret = Arrays.deepToString(array);
        System.out.println(ret);
    }
    public static void main9(String[] args) {
        int[][] array1 = new int[2][3];
        int[][] array2 = new int[][]{{1,2,3},{4,5,6}};
        int[][] array3 = {{1,2,3},{4,5,6}};

    }

    public static int find(int[] array, int key){
        for (int i = 0; i < array.length; i++) {
            if(array[i] == key){
                return i;
            }
        }
        return -1;
    }

    public static int binarySearch(int[] array, int key){
        int left = 0;
        int right = array.length-1;
        while (left <= right){
            int mid = (left+right)/2;
            if(array[mid] > key){
                right = mid-1;
            }else if(array[mid] < key){
                left = mid+1;
            }else {
                return mid;
            }
        }

        return -1;
    }

    public static void main8(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        int ret = Arrays.binarySearch(array, 9);
        System.out.println(ret);
    }

    public static void main7(String[] args) {
        int[] array = {1,5,6,4,7,9,8,2,3,0};
        Arrays.sort(array);
        System.out.println("array:" + Arrays.toString(array));
    }

    public static void bubbleSort(int[] array){
        for (int i = 0; i < array.length-1; i++) {
            boolean flag = false;
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flag = true;
                }
            }

            if(!flag){
                break;
            }
        }
    }

    public static void main6(String[] args) {
        int[] array = {1,2,3,4,5,6};
        reverse(array);
        System.out.println("array:" + Arrays.toString(array));
    }

    public static void reverse(int[] array){
        int left = 0;
        int right = array.length-1;
        while(left < right){
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            left++;
            right--;
        }
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = Arrays.copyOf(array, array.length*2);

        System.out.println("拷贝后:");
        System.out.println("array:" + Arrays.toString(array));
        System.out.println("newArray:" + Arrays.toString(copy));

    }

    public static void main4(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] newArray = Arrays.copyOf(array, array.length);

        // [1,4)
        // int[] newArray = Arrays.copyOfRange(array, 1,4);
        // 达到扩容的效果
        // int[] newArray = Arrays.copyOfRange(array, 1,14);

        // int[] newArray = new int[array.length];
        // System.arraycopy(array, 1, newArray, 2, 3);

        System.out.println("拷贝后:");
        System.out.println("array:" + Arrays.toString(array));
        System.out.println("newArray:" + Arrays.toString(newArray));
    }

    public static int[] copyArray(int[] array){
        int[] ret = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            ret[i] = array[i];
        }
        return ret;
    }

    public static void main3(String[] args) {

        int[] array = {1,2,3,4,5};
        int[] newArray = copyArray(array);

        System.out.println("拷贝后:");
        System.out.println("array:" + Arrays.toString(array));
        System.out.println("newArray:" + Arrays.toString(newArray));
    }

    public static void main2(String[] args) {
        int[] array1 = {1,2,3,4};
        int[] array2 = new int[array1.length];

        System.out.println("拷贝前:");
        System.out.println("array1:" + Arrays.toString(array1));
        System.out.println("array2:" + Arrays.toString(array2));

        for (int i = 0; i < array1.length; i++) {
            array2[i] = array1[i];
        }

        System.out.println("拷贝后:");
        System.out.println("array1:" + Arrays.toString(array1));
        System.out.println("array2:" + Arrays.toString(array2));

        System.out.println("修改array[0]下标的值:");
        array2[0] = 100;
        System.out.println("array1:" + Arrays.toString(array1));
        System.out.println("array2:" + Arrays.toString(array2));
    }

    public static void main1(String[] args) {
        int[] array1 = {1,2,3,4};
        int[] array2 = array1;
        System.out.println("array1:" + Arrays.toString(array1));
        System.out.println("array2:" + Arrays.toString(array2));

        array2[0] = 100;
        System.out.println("array1:" + Arrays.toString(array1));
        System.out.println("array2:" + Arrays.toString(array2));
    }
}
